package com.bolt.report.business.modules.param.dto.converter;

import com.bolt.report.business.modules.param.dto.ReportDbParamDTO;
import com.bolt.report.business.modules.param.entity.ReportDbParamEntity;
import com.bolt.report.definition.ParameterDefinition;
import com.bolt.report.definition.ParameterType;

import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Created by Administrator on 2018/11/27.
 */
public class ReportDbParamConverter {
    private ReportDbParamConverter() {
// do nothing
    }

    /**
     * Entity对象转换为DTO对象
     *
     * @param reportDbParam DO对象
     * @return DTO对象
     */
    public static ReportDbParamDTO toDTO(ReportDbParamEntity reportDbParam) {
        if (Objects.isNull(reportDbParam)) {
            return null;
        }
        ReportDbParamDTO result = new ReportDbParamDTO();
        result.setId(reportDbParam.getId());

        result.setReportDbId(reportDbParam.getReportDbId());
        result.setParamName(reportDbParam.getParamName());
        result.setParamText(reportDbParam.getParamText());
        result.setParamValue(reportDbParam.getParamValue());
        result.setOrderNum(reportDbParam.getOrderNum());
        result.setParamType(reportDbParam.getParamType());
        // TODO
        return result;
    }

    public static ParameterDefinition toDefinition(ReportDbParamDTO dto) {
        if (Objects.isNull(dto)) {
            return null;
        }
        ParameterDefinition result = new ParameterDefinition();
        result.setName(dto.getParamName());
        result.setParameterType(ParameterType.valueOf(dto.getParamType()));
        result.setDefaultValue(dto.getParamValue());

        // TODO
        return result;
    }

    /**
     * DTO对象转换为Entity对象
     *
     * @param reportDbParam DO对象
     * @return VO对象
     */
    public static ReportDbParamEntity toEntity(ReportDbParamDTO reportDbParam) {
        if (Objects.isNull(reportDbParam)) {
            return null;
        }
        ReportDbParamEntity result = new ReportDbParamEntity();
        result.setId(reportDbParam.getId());
        result.setReportDbId(reportDbParam.getReportDbId());
        result.setParamName(reportDbParam.getParamName());
        result.setParamText(reportDbParam.getParamText());
        result.setParamValue(reportDbParam.getParamValue());
        result.setOrderNum(reportDbParam.getOrderNum());
        result.setParamType(reportDbParam.getParamType());

        // TODO
        return result;
    }

    /**
     * DTO对象转换为DO对象
     *
     * @param reportDbParam DO对象
     * @return VO对象
     */
    public static ReportDbParamEntity toEntity(ReportDbParamEntity result, ReportDbParamDTO reportDbParam) {
        if (Objects.isNull(reportDbParam)) {
            return null;
        }
        result.setReportDbId(reportDbParam.getReportDbId());
        result.setParamName(reportDbParam.getParamName());
        result.setParamText(reportDbParam.getParamText());
        result.setParamValue(reportDbParam.getParamValue());
        result.setOrderNum(reportDbParam.getOrderNum());
        result.setParamType(reportDbParam.getParamType());

        return result;
    }

    /**
     * 批量 Entity对象转换为DTO对象
     *
     * @param reportDbParamList Entity集合对象
     * @return DTO对象
     */
    public static Set<ReportDbParamDTO> toDTO(Collection<ReportDbParamEntity> reportDbParamList) {
        if (Objects.isNull(reportDbParamList)) {
            return null;
        }
        return reportDbParamList.stream().map(ReportDbParamConverter::toDTO).collect(Collectors.toSet());
    }

    public static Set<ReportDbParamEntity> toEntity(Set<ReportDbParamDTO> reportDbParamList) {
        if (Objects.isNull(reportDbParamList)) {
            return null;
        }
        return reportDbParamList.stream().map(ReportDbParamConverter::toEntity).collect(Collectors.toSet());
    }

    public static List<ParameterDefinition> toDefinition(Collection<ReportDbParamDTO> reportDbParamList) {
        if (Objects.isNull(reportDbParamList)) {
            return null;
        }
        return reportDbParamList.stream().map(ReportDbParamConverter::toDefinition).collect(Collectors.toList());
    }

}
